﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CSharpFunctionalExtensions;
using HandyControl.Tools.Extension;
using Prism.DryIoc;

namespace FunasrSTT.Translate.ViewModels;

/// <summary>
/// 提示对话框视图模型.
/// </summary>
[INotifyPropertyChanged]
public partial class AlertViewModel : IDialogResultable<Maybe>
{
    /// <summary>
    /// 提示对话框标题.
    /// </summary>
    [ObservableProperty] private string _title = string.Empty;

    /// <summary>
    /// 提示对话框类型.
    /// </summary>
    [ObservableProperty] private ViewModels.DialogKind _kind = ViewModels.DialogKind.Information;

    /// <summary>
    /// 提示对话框 `确认` 按钮文本.
    /// </summary>
    [ObservableProperty] private string _confirmText = string.Empty;

    /// <summary>
    /// 提示对话框消息文本.
    /// </summary>
    [ObservableProperty] private string _message = string.Empty;

    /// <inheritdoc />
    public Maybe Result { get; set; } = Maybe.None;

    /// <inheritdoc />
    public Action? CloseAction { get; set; }

    public AlertViewModel() { }

    public void Initialize(string title, ViewModels.DialogKind kind, string message, string confirmText)
    {
        Title = title;
        Kind = kind;
        Message = message;
        ConfirmText = confirmText;
    }

    /// <summary>
    /// 对话框确定操作.
    /// </summary>
    [RelayCommand]
    private void Confirm()
    {
        CloseAction?.Invoke();
    }
}
